<?php
include_once "configs/smartmain.php";
include_once 'Util/MyStringUtil.php';

class TableInfo {
	public $Field;
	//public $Type;
	//public $Null;
	//public $Key;
	//public $Default;
	public $enableEscape;
	public $Extra;
	public $attribute;
	public $newType;
	public $newTypeSize;
}

class TableObject {
	
	public $data;
	public $tableName;
	public $aliasName;
	public $columnSize;
	public $definedTableName;
}

if (isset ( $_REQUEST ["info"] )) {
	$info = $_REQUEST ["info"];
} else {
	$info = "";
}

//echo base64_decode(base64_encode("aabb"))."<br //>";


//echo "info:$info <br //>";


$deinfo = base64_decode ( $info );

//echo "deinfo:$deinfo <br //>";
$ra = MyStringUtil::Tokenizer ( $deinfo, "&" );

$myrequire = array ();
foreach ( $ra as $v ) {
	$kv = MyStringUtil::Tokenizer ( $v, ":" );
	$key = $kv [0];
	if (isset ( $kv [1] )) {
		$value = $kv [1];
	} else {
		$value = "";
	}
	
	$myrequire [base64_decode ( $key )] = base64_decode ( $value );
	//echo base64_decode ( $key )." ==>value:".base64_decode ( $value )."<br //>";
}

$totalTables = $myrequire ["tableSize"];
$tables = array ();
for($i1 = 0; $i1 < $totalTables; $i1 ++) {
	$tn = "tableName" . $i1;
	$an = "aliasName" . $i1;
	
	$cSize = $myrequire ['columnSize' . $i1];
	
	$temp = new TableObject ( );
	$temp->tableName = $myrequire [$tn];
	$temp->aliasName = $myrequire [$an];
	$temp->definedTableName=$myrequire ["definedTableName" . $i1];
	
	//echo "Table name:".$temp->tableName.",alias:".$temp->aliasName."<br //>";
	$temp->data = array ();
	
	//echo "start <p>";
	for($counter = 0; $counter < $cSize; $counter ++) {
		
		$one = new TableInfo ( );
		$one->Field = $myrequire ["field" . $i1 . "_" . $counter];
		$one->newType = $myrequire ["newType" . $i1 . "_" . $counter];
		if (stristr ( $one->newType, "char" ) || stristr ( $one->newType, "text" ) || stristr ( $one->newType, "log" )) {
			$one->enableEscape = 1;
		} else {
			$one->enableEscape = 0;
		}
		$one->Extra = $myrequire ["extra" . $i1 . "_" . $counter];
		$one->newTypeSize = $myrequire ["newTypeSize" . $i1 . "_" . $counter];
		$one->attribute = $myrequire ["attribute" . $i1 . "_" . $counter];
		
		//echo "c:"."field" . $i1 . "_" . $counter."<br //>";
		//echo "f:".$one->Field."<br //>";
		$temp->data [] = $one;
	
	}
	$temp->columnSize = count ( $temp->data );
	//echo "ss:".$temp->columnSize."<br //>";
	//echo "ss:".$temp->data[0]->Field."<br //>";
	$tables [] = $temp;
}

//echo $myrequire ["joinSql"]."<br //>";

$template->assign ( "info", $info );
$template->assign ( "tables", $tables );
$template->assign ( "className", $myrequire ["className"] );
$template->assign ( "joinSql", $myrequire ["joinSql"] );
$template->assign ( "dbClassPath", $myrequire ["dbClassPath"] );
$template->assign ( "tableSize", $totalTables );
$template->display ( 'Helper.tpl.html' );

?>